<?php
	class RegisterController
	{
		// Membervariables
		private $_registerHandler = null;
		
		public function __construct(\RegisterHandler $registerHandler)
		{
			$this->_registerHandler = $registerHandler;
		}
		
		public function DoControl()
		{
			$view = new RegisterView();
			$xhtml = $view->DoRegisterForm(null);
			
			// Check wether the user clicked the button to register or not.
			if ($view->TriedToRegister() == true)
			{
				// If he did check wether the input was valid or not.
				$temp = $this->_registerHandler->ValidateInput($view->GetUserInfo(UserView::USER));
				
				// If the input was invalid return an error-message.
				if($temp != null)
				{
					$view->UserErrorMessage($temp);
				}
				else
				{
					// Get the userinfo.
					$userInfo = $view->GetUserInfo(UserView::USER);
					
					// Filter the userinfo.
					$userInfo = $this->_registerHandler->FilterUserInput($userInfo);
					
					// Generate a user-object from the info.
					$user = $this->_registerHandler->GenerateUserobjectFromUserinfo($userInfo);

					// Register the user.
					$this->_registerHandler->DoRegisterUser($user);					
				}
			}
			
			return $xhtml;
		}
	}		